<template>
	<view class="wrap-mine-info" :style="'padding-top:' + statusHeight + 'px;'" v-if="userInfo">
		<image
			class="bg-img"
			mode="widthFix"
			:src="userInfo.bg_img"
		/>
		
		
		<view class="wrap-navigation-bar flex align-center just-between">
			<view class="navigation-left flex align-center">
				<view class="add-friend flex align-center">
					<image class="img" src="/static/images/add_friend.png" />
					
					<view>添加朋友</view>
				</view>
			</view>
			
			<view class="navigation-right flex align-center">
				<view class="right-box flex align-center just-center">
					<image class="img" src="/static/images/fangke.png" />
					
					<view>新访客 99+</view>
				</view>
				
				<view class="right-box flex align-center just-center">
					<image class="img" src="/static/images/search.png" />
				</view>
				
				<view class="right-box flex align-center just-center" @click.stop="onMenu">
					<image class="img" src="/static/images/menu.png" />
				</view>
			</view>
		</view>
	
		<view class="user-info flex align-center">
			<view class="avatar-box">
				<image
					class="avatar"
					:src="userInfo.avatar"
					@click="onAvatar"
				/>
			</view>
			
			<view class="info">
				<view class="nickname-box flex align-center">
					<view class="nickname" @click="onNickName">
						{{ userInfo.nickname }}
					</view>
					
					<view class="change-box flex align-center just-center">
						<image
							class="img"
							src="/static/images/arrow_down_white.png"
						/>
					</view>
				</view>
				
				<view class="num-box flex align-center" @click="onDYH">
					<view>
						抖音号：{{ userInfo.dy_num }}
					</view>
					
					<image class="code-img" src="/static/images/qr_code.png" />
				</view>
			</view>
		</view>
	
		<view class="wrap-white-content">
			<view class="options-box flex align-center just-between">
				<view class="options-bg flex align-center">
					<view class="options-item flex column align-center just-center" @click="onZan">
						<view class="num">
							{{ parseFloat(userInfo.zan_num) > 9999 ? `${(userInfo.zan_num / 10000).toFixed(2)}万` : userInfo.zan_num }}
						</view>
						
						<view class="title">
							获赞
						</view>
					</view>
					
					<view class="options-item flex column align-center just-center" @click="onHuGuan()">
						<view class="num">
							{{ parseFloat(userInfo.hz_num) > 9999 ? `${(userInfo.hz_num / 10000).toFixed(2)}万` : userInfo.hz_num }}
						</view>
						
						<view class="title">
							互关
						</view>
					</view>
					
					<view class="options-item flex column align-center just-center" @click="onGuanZhu">
						<view class="num">
							{{ parseFloat(userInfo.gz_num) > 9999 ? `${(userInfo.gz_num / 10000).toFixed(2)}万` : userInfo.gz_num }}
						</view>
						
						<view class="title">
							关注
						</view>
					</view>
					
					<view class="options-item flex column align-center just-center" @click="onFans">
						<view class="num">
							{{ parseFloat(userInfo.fans) > 9999 ? `${(userInfo.fans / 10000).toFixed(2)}万` : userInfo.fans }}
						</view>
						
						<view class="title">
							粉丝
						</view>
					</view>
				</view>
				
				<view class="edit-page" @click="onChooseBg">
					编辑主页
				</view>
			</view>
			
			<view class="sign-box flex align-center" @click="onSign()">
				<block v-if="userInfo.sign === ''">
					<view>
						点击添加介绍，让大家认识你...
					</view>
					
					<image
						class="edit"
						src="/static/images/edit.png"
					/>
				</block>
				
				<text v-else>
					{{ userInfo.sign }}
				</text>
			</view>
			
			<view class="sex-address flex align-center">
				<view class="sex-box flex align-center" @click="onAge">
					<image
						class="sex"
						src="/static/images/sex_boy.png"
					/>
					
					<view>{{ userInfo.age }}岁</view>
				</view>
				
				<view class="address flex align-center">
					{{ userInfo.province }}·{{ userInfo.city }}
				</view>
			</view>
			
			<view class="menu-list flex align-center just-between">
				<view class="menu-item flex column align-center">
					<image
						class="img"
						src="/static/images/dysc.png"
					/>
					
					<view>抖音商城</view>
				</view>
				
				<view class="menu-item flex column align-center">
					<image
						class="img"
						src="/static/images/gkjl.png"
					/>
					
					<view>观看历史</view>
				</view>
				
				<view class="menu-item flex column align-center">
					<image
						class="img"
						src="/static/images/wdqb.png"
					/>
					
					<view>我的钱包</view>
				</view>
				
				<view class="menu-item flex column align-center">
					<image
						class="img"
						src="/static/images/wdkf.png"
					/>
					
					<view>我的客服</view>
				</view>
				
				<view class="menu-item flex column align-center">
					<image
						class="img"
						src="/static/images/qbgn.png"
					/>
					
					<view>全部功能</view>
				</view>
			</view>
		</view>
		
		<view class="wrap-bottom-list">
			<view class="wrap-tab flex">
				<view class="tab-item active">
					作品
				</view>
				
				<view class="tab-item">
					私密
				</view>
				
				<view class="tab-item">
					收藏
				</view>
				
				<view class="tab-item">
					喜欢
				</view>
			</view>
			
			<view class="wrap-list flex">
				<block v-for="(item, index) in list" :key="index">
					<view class="work-item flex column align-center" @click="onWorkItem(index)">
						<view class="title">
							{{ item.title }}
						</view>
						
						<image 
							class="file"
							:src="item.file"
						/>
						
						<view class="play-num-box flex align-center">
							<image class="play" src="/static/images/play.png" />
							
							<view>{{ item.number }}</view>
						</view>
					</view>
				</block>
			</view>
		</view>
		
		<popupVue
			:isShow.sync="isShowPopup"
			:changeKey="chooseType"
			@onRefresh="$emit('onRefresh')"
		/>
	</view>
</template>

<script>
	import popupVue from "../popup/popup.vue";
	export default {
		components: {
			popupVue
		},
		props: {
			/**
			 * 用户信息
			 */
			userInfo: {
				type: Object,
				default: null,
			},
			/**
			 * 列表
			 */
			list: {
				type: Array,
				default: [],
			}
		},
		data() {
			return {
				statusHeight: uni.getWindowInfo()["statusBarHeight"],
				
				isShowPopup: false,
				chooseType: "", //修改的类型
			}
		},
		methods: {
			/**
			 * 点击菜单
			 */
			onMenu() {
				this.$emit("onMenu");
			},
			/**
			 * 选择背景
			 */
			onChooseBg() {
				this.$filters.onChooseImage(1, list => {
					var img = list[0];
					var obj = {...this.$stoarge.getUserInfo()};
					obj.bg_img = img;
					this.$stoarge.setUserInfo(obj);
					this.$emit("onRefresh");
				})
			},
			/**
			 * 头像
			 */
			onAvatar() {
				this.$filters.onChooseImage(1, list => {
					var img = list[0];
					var obj = {...this.$stoarge.getUserInfo()};
					obj.avatar = img;
					this.$stoarge.setUserInfo(obj);
					this.$emit("onRefresh");
				})
			},
			/**
			 * 昵称
			 */
			onNickName() {
				this.chooseType = "nickname";
				this.isShowPopup = true;
			},
			/**
			 * 抖音号
			 */
			onDYH() {
				this.chooseType = "dy_num";
				this.isShowPopup = true;
			},
			/**
			 * 获赞
			 */
			onZan() {
				this.chooseType = "zan_num";
				this.isShowPopup = true;
			},
			/**
			 * 互关
			 */
			onHuGuan() {
				this.chooseType = "hz_num";
				this.isShowPopup = true;
			},
			/**
			 * 关注
			 */
			onGuanZhu() {
				this.chooseType = "gz_num";
				this.isShowPopup = true;
			},
			/**
			 * 粉丝
			 */
			onFans() {
				this.chooseType = "fans";
				this.isShowPopup = true;
			},
			/**
			 * 简介
			 */
			onSign() {
				this.chooseType = "sign";
				this.isShowPopup = true;
			},
			/**
			 * 年龄
			 */
			onAge() {
				this.chooseType = "age";
				this.isShowPopup = true;
			},
			/**
			 * 作品
			 */
			onWorkItem(index) {
				uni.navigateTo({
					url: `/pages/add/add?index=${index}`
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.wrap-mine-info {
		width: 100%;
		overflow: hidden;
		position: relative;
		z-index: 1;
		
		.bg-img {
			position: absolute;
			left: 0rpx;
			top: 0rpx;
			width: 100%;
			overflow: hidden;
			z-index: 2;
		}
		
		.wrap-navigation-bar {
			width: 100%;
			height: 45px;
			padding: 0rpx 30rpx;
			box-sizing: border-box;
			overflow: hidden;
			background-color: transparent;
			position: relative;
			z-index: 3;
			
			.navigation-left {
				overflow: hidden;
				
				.add-friend {
					padding: 7px;
					box-sizing: border-box;
					height: 30px;
					overflow: hidden;
					border-radius: 15px;
					background-color: rgba(0, 0, 0, 0.3);
					gap: 10rpx;
					color: #ffffff;
					font-size: 24rpx;
					
					.img {
						width: 16px;
						height: 16px;
					}
				}
			}
			
			.navigation-right {
				gap: 20rpx;
				overflow: hidden;
				
				.right-box {
					padding: 7px;
					box-sizing: border-box;
					height: 30px;
					overflow: hidden;
					border-radius: 15px;
					background-color: rgba(0, 0, 0, 0.3);
					gap: 10rpx;
					color: #ffffff;
					font-size: 24rpx;
					
					.img {
						width: 16px;
						height: 16px;
					}
				}
			}
		}
	
		.user-info {
			width: 100%;
			padding: 30rpx;
			box-sizing: border-box;
			overflow: hidden;
			position: relative;
			z-index: 3;
			gap: 30rpx;
			
			.avatar-box {
				width: 160rpx;
				height: 160rpx;
				border-radius: 100%;
				border: 5rpx solid white;
				overflow: hidden;
				
				.avatar {
					width: 100%;
					height: 100%;
				}
			}
			
			.info {
				flex: 1;
				overflow: hidden;
				
				.nickname-box {
					width: 100%;
					overflow: hidden;
					gap: 10rpx;
					
					.nickname {
						--limit-num: 1;
						color: white;
						font-size: 46rpx;
					}
					
					.change-box {
						width: 50rpx;
						height: 50rpx;
						border-radius: 100%;
						overflow: hidden;
						background-color: rgba(0, 0, 0, 0.3);
						flex-shrink: 0;
						
						.img {
							width: 32rpx;
							height: 32rpx;
						}
					}
				}
				
				.num-box {
					margin-top: 10rpx;
					width: 100%;
					overflow: hidden;
					gap: 15rpx;
					color: #BBBBBB;
					font-size: 26rpx;
					
					.code-img {
						flex-shrink: 0;
						width: 26rpx;
						height: 26rpx;
						overflow: hidden;
					}
				}
			}
		}
	
		.wrap-white-content {
			width: 100%;
			overflow: hidden;
			background-color: white;
			padding: 30rpx;
			box-sizing: border-box;
			border-top-left-radius: 50rpx;
			border-top-right-radius: 50rpx;
			position: relative;
			z-index: 3;
			
			.options-box {
				width: 100%;
				overflow: hidden;
				gap: 20rpx;
				
				.options-bg {
					flex: 1;
					overflow: hidden;
					gap: 30rpx;
					
					.options-item {
						gap: 10rpx;
						
						.num {
							color: #000000;
							font-size: 28rpx;
							font-weight: 900;
						}
						
						.title {
							color: #666666;
							font-size: 30rpx;
						}
					}
				}
				
				.edit-page {
					width: 200rpx;
					height: 80rpx;
					line-height: 80rpx;
					text-align: center;
					background-color: #DDDDDD;
					color: #333333;
					font-size: 28rpx;
				}
			}
			
			.sign-box {
				margin-top: 40rpx;
				width: 100%;
				overflow: hidden;
				color: #666666;
				font-size: 28rpx;
				gap: 20rpx;
				
				.edit {
					flex-shrink: 0;
					width: 28rpx;
					height: 28rpx;
				}
			}
			
			.sex-address {
				margin-top: 15rpx;
				width: 100%;
				overflow: hidden;
				gap: 20rpx;
				
				.sex-box {
					height: 40rpx;
					color: #666666;
					font-size: 26rpx;
					padding: 0rpx 15rpx;
					box-sizing: border-box;
					background-color: #EEEEEE;
					gap: 15rpx;
					
					.sex {
						width: 20rpx;
						height: 20rpx;
					}
				}
				
				.address {
					height: 40rpx;
					color: #666666;
					font-size: 26rpx;
					padding: 0rpx 15rpx;
					box-sizing: border-box;
					background-color: #EEEEEE;
				}
				
				
				
			}
			
			.menu-list {
				margin-top: 40rpx;
				width: 100%;
				overflow: hidden;
				
				.menu-item {
					overflow: hidden;
					gap: 15rpx;
					color: #333333;
					font-size: 26rpx;
					
					.img {
						width: 40rpx;
						height: 40rpx;
					}
				}
			}
			
		}
		
		.wrap-bottom-list {
			padding-top: 50rpx;
			width: 100%;
			overflow: hidden;
			position: relative;
			z-index: 102;
			background-color: white;
			
			.wrap-tab {
				width: 100%;
				overflow: hidden;
				
				.tab-item {
					flex: 1;
					height: 80rpx;
					line-height: 80rpx;
					text-align: center;
					border-bottom: 6rpx solid #ffffff;
					color: #666666;
					font-size: 28rpx;
				}
				
				.active {
					color: #000000 !important;
					border-bottom-color: #333333;
				}
			}
			
			.wrap-list {
				border-top: 2rpx solid #EEEEEE;
				width: 100%;
				overflow: hidden;
				padding: 30rpx 0rpx;
				box-sizing: border-box;
				flex-wrap: wrap;
				gap: 7.5rpx;
				
				.work-item {
					width: 245rpx;
					background-color: #F6F6F6;
					overflow: hidden;
					padding: 30rpx 30rpx 80rpx 30rpx;
					box-sizing: border-box;
					position: relative;
					
					.title {
						color: #333333;
						font-size: 28rpx;
					}
					
					.file {
						margin-top: 50rpx;
						width: 120rpx;
						height: 120rpx;
						overflow: hidden;
					}
					
					.play-num-box {
						position: absolute;
						left: 0rpx;
						bottom: 0rpx;
						width: 100%;
						height: 60rpx;
						background-color: rgba(0, 0, 0, 0.1);
						color: white;
						padding: 0rpx 15rpx;
						box-sizing: border-box;
						font-size: 24rpx;
						gap: 10rpx;
						
						.play {
							width: 30rpx;
							height: 30rpx;
						}
					}
				}
			}
		}
	}
</style>